define(function(){
    class Login{
            constructor(options){
                 this.user = options.ouser
                this.pass = options.opass
                this.btn = options.obtn
                this.span = options.ospan

                this.addEvent();
                this.getLocal();
            }
            addEvent(){
                var that = this;
                this.btn.onclick = function(){
                    that.login();
                }
            }
            getLocal(){
                // 之前有没有
                this.userMsg = localStorage.getItem("userMsg");
                this.userMsg = this.userMsg ? JSON.parse(this.userMsg) : [];
            }
             login(){
                var i = 0;
                var o = this.userMsg.some((val,index)=>{
                    i = index;
                    return val.user == this.user.value && val.pass == this.pass.value;
                })
                if(o){
                    this.span.innerHTML = "<em style='color:green'>登录成功，2秒后跳转</em>";
                    this.userMsg[i].onoff = 1;
                    setTimeout(() => {
                        location.href = "index.html";
                    }, 2000);
                }else{
                    this.span.innerHTML = "<em style='color:red'>账号或密码错误</em>";
                }
                localStorage.setItem("userMsg",JSON.stringify(this.userMsg))
            }
        }
		
		return {
			log1:Login
		}
});